package id.net.iconpln.bb.client.view;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.grid.AggregationRenderer;
import com.extjs.gxt.ui.client.widget.grid.AggregationRowConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.grid.SummaryType;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.table.NumberCellRenderer;
import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Element;

public class PageRekapBbMonKwalitas extends LayoutContainer{
	private ContentPanel cp;
	private Grid laypanel;
	private Grid grid;
	private GroupingStore store;
	Window window;
	FormData formData;
	
	final NumberFormat currency = NumberFormat.getCurrencyFormat();  
    final NumberFormat number = NumberFormat.getFormat("0.00");  
    final NumberCellRenderer<Grid> numberRenderer = new NumberCellRenderer<Grid>(currency); 
	
	 @Override
	  protected void onRender(Element parent, int pos) {
	    super.onRender(parent, pos); 
	    setLayout(new FitLayout());
	    final ToolBar toolBar = new ToolBar();
	    ToolBar toolBar1 = new ToolBar();
	    formData = new FormData("-20");
		
	    
	    Button btconfigure = new Button("Konfigurasi", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {
		    	  
//		    	  	FormPanel simple = new FormPanel();  
//				    simple.setHeaderVisible(false);
//				    simple.setFrame(true);
//				    simple.setAutoHeight(true);
//				    simple.setWidth(350); 
//				    
//				    final SimpleComboBox<String> pemasok = new SimpleComboBox<String>();  
//				    pemasok.setFieldLabel("Pemasok"); 			    
//				    simple.add(pemasok, formData);
//				    
//				    final SimpleComboBox<String> nokontrak = new SimpleComboBox<String>();  
//				    nokontrak.setFieldLabel("No Kontrak"); 			    
//				    simple.add(nokontrak, formData);
//				    
//				    final SimpleComboBox<String> param = new SimpleComboBox<String>();  
//				    param.setFieldLabel("Parameter"); 			    
//				    simple.add(param, formData);
//				    
//				    final SimpleComboBox<String> basis = new SimpleComboBox<String>();  
//				    basis.setFieldLabel("Basis"); 			    
//				    simple.add(basis, formData);
//				    
//				    simple.setButtonAlign(HorizontalAlignment.LEFT);  
//				    simple.addButton(new Button("Cancel", new SelectionListener<ButtonEvent>() {  
//				      @Override  
//				      public void componentSelected(ButtonEvent ce) {  
//				    	window.close();
//				      }  
//				    }));  
//				    simple.addButton(new Button("Simpan", new SelectionListener<ButtonEvent>() {  
//				      @Override  
//				      public void componentSelected(ButtonEvent ce) {
//				    	  
//				    	  
//					      }  
//				    }));  
//				    
//				    simple.setButtonAlign(HorizontalAlignment.CENTER); 
//		    	  
//		    	  
//		    	  	window = new Window();  
//				    window.setHeading("Parameter Laporan"); 
//				    window.setLayout(new FitLayout());
//				    window.setAutoHeight(true);
//				    window.setWidth(600);
//				    window.setScrollMode(Scroll.AUTO);
//				    window.add(simple);
//				    
//		        	window.show();
		    	  
		    	  
		      }  
		    });  
		    
	    btconfigure.setIcon(IconHelper.createStyle("icon-reza-configure"));
	    
	    cp = new ContentPanel();
		cp.setLayoutOnChange(true); 
		cp.setCollapsible(false);
		cp.setFrame(false);
		cp.setLayout(new FitLayout());
		cp.setBorders(false);
		cp.setHeaderVisible(false);
		
		final SimpleComboBox<String> pemasok = new SimpleComboBox<String>();  
	    pemasok.setEmptyText("Pilih Pemasok.."); 
	    
	    final SimpleComboBox<String> nokontrak = new SimpleComboBox<String>();  
	    nokontrak.setEmptyText("Pilih No Kontrak.."); 
	    
	    Button btcetak = new Button("Cetak", new SelectionListener<ButtonEvent>() {  
		      @Override  
		      public void componentSelected(ButtonEvent ce) {
		    	  
		      }  
		    });  
	    btcetak.setIcon(IconHelper.createStyle("icon-printer"));
		
		
//    	toolBar.add(new LabelToolItem("<b>Perbandingan Analisa Kualitas Batubara <br> PT.INDONESIA COMNETS PLUS <BR> NO KONTRAK 08.SPK/061/IP/2009"));
		toolBar.add(new LabelToolItem("<b>Perbandingan Analisa Kualitas Batubara &nbsp;"));
		toolBar.add(pemasok);
		toolBar.add(new LabelToolItem("<b>&nbsp;No Kontrak:&nbsp;"));
		toolBar.add(nokontrak);
		toolBar.add(new SeparatorToolItem());
		toolBar.add(btcetak);
//    	toolBar.setAlignment(HorizontalAlignment.CENTER);
//    	toolBar1.add(btconfigure);
//		toolBar1.add(new SeparatorToolItem());
    	cp.setTopComponent(toolBar);
//    	cp.setBottomComponent(toolBar1);
    	cp.syncSize();

		laypanel = task();
		cp.add(laypanel);  
	  
			
		add(cp, new FitData(5));
	}
	 
	private Grid task(){
		   	
			List<ColumnConfig> configs = new ArrayList<ColumnConfig>();  
		    
		   	store = new GroupingStore();  
		    getDataGrid();
		   
		    RowNumberer rn = new RowNumberer();  
		    rn.setWidth(30);  
		    configs.add(rn);  
		    
		    ColumnConfig column = new ColumnConfig();  
		    
		    column = new ColumnConfig();  
		    column.setId("name");  
		    column.setHeader("<center>Tanggal Selesai Bongkar");  
		    column.setWidth(150);  
		    configs.add(column);  
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Kapal");  
		    column.setWidth(330);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>TUG3 <br>(Kg)");  
		    column.setWidth(150);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Loading");  
		    column.setWidth(150);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Unloading");  
		    column.setWidth(150);  
		    configs.add(column); 
		    
		    column = new ColumnConfig();  
		    column.setId("");  
		    column.setHeader("<center>Labor");  
		    column.setWidth(150);  
		    configs.add(column); 
	
			
		    
		    ColumnModel cm = new ColumnModel(configs);
		    cm.addHeaderGroup(0, 4, new HeaderGroupConfig("Abu (Ash)<br>(% by weight in AR)", 1, 3)); 
		    
		    grid = new Grid(store, cm);  
		    grid.setBorders(false);
		      
		    
		return grid;
	}
	  
	
	private void getDataGrid() {
	
	}
	
	
}